package doublelist;

import java.util.*;

public class HashMapDemo {
    public static void main(String[] args) {
        HashMap<Student,String> hm = new HashMap<>();
        Student stu1 = new Student("张三",18);
        Student stu2 = new Student("李四",19);
        Student stu3 = new Student("王五",20);
        hm.put(stu1,"湖北");
        hm.put(stu2,"湖南");
        hm.put(stu3,"河北");
        Set<Student> keys = hm.keySet();
        for (Student key : keys) {
            String value = hm.get(key);
            System.out.println(key+"="+value);
        }

        List<String> option = List.of("A","B","C","D");
        ArrayList<String> list = new ArrayList<>();
        for(int i=0;i<80;i++){
            int random = (int)(Math.random()*4);
            list.add(option.get(random));
        }
        HashMap<String,Integer> m2 = new HashMap<>();
        for(String s:list){
         if(m2.containsKey(s)){
             m2.put(s,m2.get(s)+1);
         }else{
             m2.put(s,1);
         }
        }
        System.out.println(m2);
        int max = 0;
        for (Integer value : m2.values()) {
            if(value>max){
                max = value;
            }
        }
        System.out.println(max);
        for (String key : m2.keySet()) {
            if(m2.get(key)==max){
                System.out.println(key);
            }
        }



    }
}
